package com.registration.controller;

import com.github.pagehelper.PageInfo;
import com.registration.Annotation.OperateLog;
import com.registration.bean.LogBean;
import com.registration.service.LogService;
import com.registration.util.JsonResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/log")
@CrossOrigin
public class LogController {

    @Autowired
    private LogService logService;

    @GetMapping("/list")
    @OperateLog("分页查询日志")
    public JsonResponse list( @RequestParam(defaultValue = "1") int pageNum, @RequestParam(defaultValue = "10") int pageSize) {
        JsonResponse response = new JsonResponse();
        try {
            // 限制每页最大记录数
            if (pageSize > 50) {
                pageSize = 50;
            }
            PageInfo<LogBean> pageInfo = logService.selectLogsByPage(pageNum, pageSize);
            response.setCode(0);
            response.setMsg("查询成功");
            response.setData(pageInfo);
        } catch (Exception e) {
            response.setCode(1);
            response.setMsg("查询失败: " + e.getMessage());
            e.printStackTrace();
        }
        return response;
    }

}
